<?php
declare(strict_types=1);

namespace app\admin\service;

use app\admin\model\ResourceSaleWallet;

class ResourceSaleWalletService
{
    /**
     * 创建钱包（收益）
     * @param $data
     * @return ResourceSaleWallet
     */
    public static function createResourceSaleWallet($data)
    {
        return ResourceSaleWallet::createResourceSaleWallet($data);

    }

    /**
     * 钱包收益数据
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getResourceSaleWallet($where)
    {
        $data = ResourceSaleWallet::getResourceSaleWallet($where);
        // 支出金额
        $expensesPrice = 0;
        // 平台收益
        $platformPrice = 0;
        foreach ($data as $val) {
            $expensesPrice += $val['balance'];
            $lastPrice = $val['original_income'] - $val['balance'];
            $platformPrice += $lastPrice;
        }

        return ['expensesPrice' => $expensesPrice, 'platformPrice' => $platformPrice];
    }
}